/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.lodz.p.ftims.ProjektZespolowy2.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Łukasz Gadomski
 */
@Entity
@Table(name = "object_types")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ObjectType.findAll", query = "SELECT o FROM ObjectType o"),
    @NamedQuery(name = "ObjectType.findByObjectTypeId", query = "SELECT o FROM ObjectType o WHERE o.objectTypeId = :objectTypeId"),
    @NamedQuery(name = "ObjectType.findByName", query = "SELECT o FROM ObjectType o WHERE o.name = :name")})
public class ObjectType implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "object_type_id")
    private Integer objectTypeId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "objectTypeId")
    private Collection<Objects> objectsCollection;

    public ObjectType() {
    }

    public ObjectType(Integer objectTypeId) {
        this.objectTypeId = objectTypeId;
    }

    public ObjectType(Integer objectTypeId, String name) {
        this.objectTypeId = objectTypeId;
        this.name = name;
    }

    public Integer getObjectTypeId() {
        return objectTypeId;
    }

    public void setObjectTypeId(Integer objectTypeId) {
        this.objectTypeId = objectTypeId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Objects> getObjectsCollection() {
        return objectsCollection;
    }

    public void setObjectsCollection(Collection<Objects> objectsCollection) {
        this.objectsCollection = objectsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (objectTypeId != null ? objectTypeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ObjectType)) {
            return false;
        }
        ObjectType other = (ObjectType) object;
        if ((this.objectTypeId == null && other.objectTypeId != null) || (this.objectTypeId != null && !this.objectTypeId.equals(other.objectTypeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.lodz.p.ftims.ProjektZespolowy2.entities.ObjectTypes[ objectTypeId=" + objectTypeId + " ]";
    }
    
}
